import { AGE_MODLE, NVALID_VALUE } from "./model/calory-calculator.model";

export abstract class BaseSexCaloryCalculator {
    age: number;
    weight: number;

    constructor(age: number, weight: number) {
        this.age = age;
        this.weight = weight;
    }

    caloricCalculate() {
        return this.getAgeRangeCalculateFn().call(this);
    }

    getAgeRangeCalculateFn() {
        if (this.age < AGE_MODLE.EIGHTEEN) return this.nonageCaloricCalculate;
        if (this.age >= AGE_MODLE.EIGHTEEN && this.age <= AGE_MODLE.THIRTY) return this.juvenileCaloricCalculate;
        if (this.age >= AGE_MODLE.THIRTY_ONE && this.age <= AGE_MODLE.SIXTY) return this.youthCaloricCalculate;
        if (this.age > AGE_MODLE.SIXTY) return this.agedCaloricCalculate;
        return this.illegalCaloricCalculate;
    }

    abstract nonageCaloricCalculate(): number;
    abstract juvenileCaloricCalculate(): number;
    abstract youthCaloricCalculate(): number;
    abstract agedCaloricCalculate(): number;
    illegalCaloricCalculate() {
        return NVALID_VALUE;
    }
}
